package javaCode.chapter13.map_;

import com.sun.crypto.provider.HmacPKCS12PBESHA1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 徐州城
 * @version 1.0
 */
@SuppressWarnings("all")
public class MapMethod {
    public static void main(String[] args) {
        //演示Map接口常用方法

        Map map = new HashMap();
        map.put("邓超", new Book("", 100));
        map.put("邓超", "孙俪");
        map.put("王宝强", "马蓉");
        map.put("宋喆", "马蓉");
        map.put("鹿晗", "关晓彤");

        System.out.println("map=" + map);

        //remove：根据键删除映射关系
        System.out.println("map=" + map.remove("宋喆"));
        //get：根据键获取值
        System.out.println(map.get("鹿晗"));
        //size：获取元素的个数
        System.out.println("k-v=" + map.size());
        //isEmpty：判断个数是否为0
        System.out.println(map.isEmpty()); //f
        //clear：清除k-v
        map.clear();
        //containsKey：查找键是否存在
        System.out.println(map.containsKey("hso"));
    }
}

class Book {
    private String name;
    private int num;

    public Book(String name, int num) {
        this.name = name;
        this.num = num;
    }
}